package
cn.atide;

import org.gdal.gdal.gdal;
import org.gdal.ogr.DataSource;
import org.gdal.ogr.Driver;
import org.gdal.ogr.Layer;
import org.gdal.ogr.ogr;
import org.junit.Test;
/ **
*读取cad数据
* @ author
Administrator
*
* /
public


class ReadDxf {

@ Test
public void test() {
// 注册所有的驱动
ogr.RegisterAll();
gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");
gdal.SetConfigOption("SHAPE_ENCODING", "");
String strVectorFile = "E:\\gdalTest\\output\\财信.渝中城项目5#楼竣工.dxf";
DataSource ds = ogr.Open(strVectorFile, 0);
if (ds == null)
{
System.out.println("打开文件失败！" );


return;
}
System.out.println("打开文件成功！");
int
iLayerCount = ds.GetLayerCount();
Layer
oLayer = ds.GetLayerByIndex(0);
String
name = oLayer.GetName();
if (oLayer == null)
{
System.out.println("获取失败");
return;
}
oLayer.ResetReading();
long
featureCount = oLayer.GetFeatureCount();
// Driver
dv = ogr.GetDriverByName("GeoJSON");
Driver
dv = ogr.GetDriverByName("ESRI Shapefile");
String
extfile = "D:\\rect_field_demo.shp";
DataSource
dataSource = dv.CreateDataSource(extfile);
dv.CopyDataSource(ds, extfile);
// dataSource.CreateLayer(name)
   / * if (dv == null)
{
System.out.println("打开驱动失败！");
return;
}
System.out.println("打开驱动成功！");
dv.CopyDataSource(ds, "E:\\gdalTest\\output\\node.json");
System.out.println("转换成功！"); * /
}
}